import this
from typing import List


def triangleNumber(self, nums: List[int]) -> int:
    n = len(nums)
    nums.sort()
    ans = 0
    for i in range(n):
        k = 1
        for j in range(i + 1, n):
            while k + 1 < n and nums[k + 1] < nums[i] + nums[j]:
                k += 1
            ans += max(k - j, 0)
    return ans


print(triangleNumber(this, [2, 2, 3, 4]))
